<?php
namespace Admin\Controller;
use Think\Controller;
class MessageController extends Controller {
    //TP构造函数
    public function _initialize(){
        //自动加载的类
        new \Org\Admin_autoload();
        //当前页仅管理员以上可以访问
        if($this->admin_info['admin_group_id']>2){
            echo "<script>alert('当前页面仅管理员以上可以访问，请您使用管理员账号登录');history.back(-1);</script>";exit;
        }
    }
    //首页留言管理
    public function index(){
        $data['title']='首页留言 留言 - 找金银网';
        if(I('path.2')!=''){
            $page=I('path.2');
        }else{
            $page=1;
        }
        $perpage=10;
        $Model=D("Message");
        //搜索 关键词
        if(I('post.keyword')){
            $Model->keyword=I('post.keyword');
        }
        //搜索 分类
        /*if(I('post.pc_id')){
            $Model->pc_id=I('post.pc_id');
        }*/
        $Model->page=$page;
        $Model->perpage=$perpage;
        $message_list=$Model->get_message_list();
        //print_r($message_list);exit;
        $message_total=$Model->get_message_total();
        //echo $user_total;exit;
        $page_total=ceil($message_total/$perpage);
        //echo $page_total;exit;
        //分页数据
        if($page!=1&&$page_total>1){
            $last_page=$page-1;
        }else{
            $last_page=1;
        }
        if($page_total>$page){
            $next_page=$page+1;
        }else{
            $next_page=$page;
        }
        $pager['current_page']=$page;
        $pager['perpage']=$perpage;
        $pager['last_page']=$last_page;
        $pager['next_page']=$next_page;
        $pager['message_total']=$message_total;
        $pager['page_total']=$page_total;
        //$cat_list=$Model->get_cat_list();
        $this->assign("message_list", $message_list);
        //$this->assign("cat_list", $cat_list);
        $this->assign("pager",$pager);
        $this->assign("data", $data);
        $this->display();
    }

    //更新排序及批量删除
    public function update_message()
    {
        if(I('post.ids')){
            $ids=I('post.ids');
            //print_r($ids);exit;
            $Model=D("Message");
            $Model->ids=$ids;
            if(!$Model->delete_message()){
                echo "<script>alert('删除失败，请您尝试重新提交');history.back(-1);</script>";exit;
            }
            echo "<script>self.location=document.referrer;</script>";exit;
        }
        /*elseif(I('post.product_ids')){
            $ids=I('post.product_ids');
            $sorts=I('post.sorts');
            $Model=D("Product");
            $Model->ids=$ids;
            $Model->sorts=$sorts;
            if(!$Model->update_product_sort()){
                echo "<script>alert('更新失败，请您尝试重新提交');history.back(-1);</script>";exit;
            }
            echo "<script>self.location=document.referrer;</script>";
        }*/
    }

    //首页物流管理
    public function logistics(){
        $data['title']='物流留言 留言 - 找金银网';
        if(I('path.2')!=''){
            $page=I('path.2');
        }else{
            $page=1;
        }
        $perpage=10;
        $Model=D("LogisticsMessage");
        //搜索 关键词
        if(I('post.keyword')){
            $Model->keyword=I('post.keyword');
        }
        //搜索 分类
        /*if(I('post.pc_id')){
            $Model->pc_id=I('post.pc_id');
        }*/
        $Model->page=$page;
        $Model->perpage=$perpage;
        $message_list=$Model->get_message_list();
        //print_r($message_list);exit;
        $message_total=$Model->get_message_total();
        //echo $message_total;exit;
        $page_total=ceil($message_total/$perpage);
        //echo $page_total;exit;
        //分页数据
        if($page!=1&&$page_total>1){
            $last_page=$page-1;
        }else{
            $last_page=1;
        }
        if($page_total>$page){
            $next_page=$page+1;
        }else{
            $next_page=$page;
        }
        $pager['current_page']=$page;
        $pager['perpage']=$perpage;
        $pager['last_page']=$last_page;
        $pager['next_page']=$next_page;
        $pager['message_total']=$message_total;
        $pager['page_total']=$page_total;
        //$cat_list=$Model->get_cat_list();
        $this->assign("message_list", $message_list);
        //$this->assign("cat_list", $cat_list);
        $this->assign("pager",$pager);
        $this->assign("data", $data);
        $this->display();
    }

    //更新排序及批量删除
    public function update_logistics()
    {
        if(I('post.ids')){
            $ids=I('post.ids');
            //print_r($ids);exit;
            $Model=D("LogisticsMessage");
            $Model->ids=$ids;
            if(!$Model->delete_message()){
                echo "<script>alert('删除失败，请您尝试重新提交');history.back(-1);</script>";exit;
            }
            echo "<script>self.location=document.referrer;</script>";exit;
        }
        /*elseif(I('post.product_ids')){
            $ids=I('post.product_ids');
            $sorts=I('post.sorts');
            $Model=D("Product");
            $Model->ids=$ids;
            $Model->sorts=$sorts;
            if(!$Model->update_product_sort()){
                echo "<script>alert('更新失败，请您尝试重新提交');history.back(-1);</script>";exit;
            }
            echo "<script>self.location=document.referrer;</script>";
        }*/
    }

}